package com.zhu.tool_test.datastructure.queue;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @program: tool_test
 * @description: 消费者
 * @author: ggBall
 * @create: 2021-03-03 16:18
 **/
public class Consumer {

    private Queue queue;

    public Consumer() {

    }

    public Consumer(Queue queue) {
        this.queue = queue;
    }

    public String consume() {
        List<String> consume = consume(1);
        if (null == consume && consume.size() == 1) {
            return consume.get(0);
        }
        return null;
    }

    public List<String> consume(Integer num) {

        LinkedList<String> strings = new LinkedList<>();

        if (queue.isEmpty()) {
            return null;
        }
        for (int i = 0; i < num; i++) {
            Object poll = queue.poll();
            strings.add(String.valueOf(poll));
        }

        return strings;
    }
}
